package com.example.administrator.videotest2.util;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;

import com.example.administrator.videotest2.FindVideoActivity;
import com.example.administrator.videotest2.Jsoup.db.Video;
import com.example.administrator.videotest2.R;
import com.example.administrator.videotest2.config.VideoApi;

import scut.carson_ho.searchview.ICallBack;
import scut.carson_ho.searchview.SearchView;
import scut.carson_ho.searchview.bCallBack;

public class Search_viewActivity extends AppCompatActivity {

    private SearchView searchView;
    private RadioButton zy1;
    private RadioButton zy2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_search_view);
        search();
    }


    /**
     * 搜索框
     */
    public void search() {
        // 2. 绑定视图
        setContentView(R.layout.activity_search_view);

        // 3. 绑定组件
        searchView = (SearchView) findViewById(R.id.search_view);


        // 4. 设置点击键盘上的搜索按键后的操作（通过回调接口）
        // 参数 = 搜索框输入的内容
        searchView.setOnClickSearch(new ICallBack() {
            @Override
            public void SearchAciton(String string) {
                Intent intent=new Intent(Search_viewActivity.this, FindVideoActivity.class);
                String type=1+"";
                zy1=findViewById(R.id.zy1);
                zy2=findViewById(R.id.zy2);
                if (zy1.isChecked()){
                    intent.putExtra("api", VideoApi.find_video);
                    type="1";
                }
                if (zy2.isChecked()){
                    intent.putExtra("api", VideoApi.zy2);
                    type="2";
                }
                if (string.replace(" ","").equals("")){
                    string=null;
                }
                intent.putExtra("title",string);
                intent.putExtra("type",type);
                startActivity(intent);
            }
        });

        // 5. 设置点击返回按键后的操作（通过回调接口）
        searchView.setOnClickBack(new bCallBack() {
            @Override
            public void BackAciton() {
                finish();

            }
        });
    }

}
